package com.weijian.dal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 课程难度等级枚举
 * 数据库中存储为整数：1-初级，2-中级，3-高级
 */
@Getter
public enum CourseLevel {
    BEGINNER(1, "初级"),
    INTERMEDIATE(2, "中级"),
    ADVANCED(3, "高级");

    @EnumValue
    private final int code;
    
    @JsonValue
    private final String description;

    CourseLevel(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public static CourseLevel fromCode(int code) {
        for (CourseLevel level : values()) {
            if (level.code == code) {
                return level;
            }
        }
        throw new IllegalArgumentException("Invalid course level code: " + code);
    }
}